<?PHP
	class Logger {
		var $loggerData;
		function Logger(){
			$this->loggerData = array();
		}
		function add($key,$value){
			$this->loggerData[] = array($key,$value,microtime());
		}
		function renderHTMLLog($separator=": ",$newline="<br />"){
			$log_result = "";
			foreach($this->loggerData as $log){
				//$log[0].$separator.
				$log_result .= "<span class=\"".$log[0]."\">[".$log[0]."] ".$log[1]."</span>".$newline;
			}
			return $log_result;
		}
		function renderLog($separator=": ",$newline="<br />"){
			$log_result = "";
			foreach($this->loggerData as $log){
				$log_result .= $log[0].$separator.$log[1].$newline;
			}
			return $log_result;
		}
		function createLog(){
			if(!isset($GLOBALS["application_debugLogger"])){
				$GLOBALS["application_debugLogger"] = new Logger();
			}
		}
		function log($key,$value){
			Logger::createLog();
			$GLOBALS["application_debugLogger"]->add($key,$value);
		}
		function render($type="HTML"){
			Logger::createLog();
			$debug = "";
			//$debug .= "<div id=\"matelog\"><h3>MATE:Log</h3>";
			//$debug .= "Application execution duration : ";
			//$totaltime = ($GLOBALS["application_endTime"] - $GLOBALS["application_startTime"]); 
			//$debug .= $totaltime." seconds<br/>";
			switch(strToLower($type)){
				case "html":
					$debug .= $GLOBALS["application_debugLogger"]->renderHTMLLog();
					break;
				case "plain":
				default:
					$debug .= $GLOBALS["application_debugLogger"]->renderLog();
					break;
			}
			
			//$debug .= "</div>";
			return $debug;
		}
		
	}
?>
